<?php
class Core_MenuService
{
	public $leftMenu = array(
		/**
		 * Strona główna
		 */
		0 => array(
			array( 
				'name' => 'left_menu_about_us',
				'action' => 'index/showstatic/id/22/'
			),
			array( 
				'name' => 'left_menu_news',
				'action' => 'index/news/type/2'
			),
			array( 
				'name' => 'left_menu_media_about_us',
				'action' => 'index/showstatic/id/23/'
			),
			array( 
				'name' => 'left_menu_press',
				'action' => 'index/showstatic/id/24'
			),
			array( 
				'name' => 'left_menu_relationships',
				'action' => 'index/news/type/1'
			)
		),
		1 => array(),
		2 => array(),/*
			array( 
				'name' => 'left_menu_autodetailing',
				'action' => 'services/static/p/asdasd',
				'p' => 'asdasd',
				'child' => array(
					array(
						'name' => 'left_menu_prepare',
						'action' => 'services/static/p/asdasd/c/prepare',
						'cstatic' => 'prepare',
						'parent' => 'asdasd'
					),
					array(
						'name' => 'left_menu_revision',
						'action' => 'services/static/p/asdasd/c/revision',
						'cstatic' => 'revision',
						'parent' => 'asdasd'
					),
					array(
						'name' => 'left_menu_renovation',
						'action' => 'services/static/p/asdasd/c/renovation',
						'cstatic' => 'renovation',
						'parent' => 'asdasd'
					),
					array(
						'name' => 'left_menu_secure',
						'action' => 'services/static/p/asdasd/c/secure',
						'cstatic' => 'secure',
						'parent' => 'asdasd'
					)
				)
			),
			array( 
				'name' => 'left_menu_smartrepair',
				'action' => 'services/static/324'
			),
			array( 
				'name' => 'left_menu_media_offer',
				'action' => 'services/static/p/asfsadf'
			),
			array( 
				'name' => 'left_menu_projects',
				'action' => 'services/static/p/3sdfsd'
			)
		),*/
		3 => array(),
		4 => array(/*
			array( 
				'name' => 'left_menu_bialystok',
				'action' => 'contact/index/p/bialystok'
			),
			array( 
				'name' => 'left_menu_warszawa',
				'action' => 'contact/index/p/warszawa'
			),
			array( 
				'name' => 'left_menu_krakow',
				'action' => 'contact/index/p/krakow'
			),
			array( 
				'name' => 'left_menu_poznan',
				'action' => 'contact/index/p/poznan'
			),
			array( 
				'name' => 'left_menu_szczecin',
				'action' => 'contact/index/p/szczecin'
			)
		*/),
		5 => array(/*
			array( 
				'name' => 'left_menu_franchise',
				'action' => 'cooperation/static/p/asdasd',
				'p' => 'asdasd'
			),
			array( 
				'name' => 'left_menu_smart',
				'action' => 'cooperation/static/324'
			)
		*/),
		6 => array()
	);
	
	public $locale;
	
	public $view;
	
	public function __construct( $locale, $view ) {
		$this->locale = $locale;
		$this->view = $view;
	}
	
	public function getMenu( $index ) {
		if( $index == 1 ) {
			$Categries = new Categries();
			
			$items = $Categries->getListService( 0, $this->locale );
			$arr1 =  $this->_arrToLeftMenu( 'shop', $items->toArray() );
			
			$Categries = new Categries();
			
			$items = $Categries->getListService( 1, $this->locale );
			$arr2 =  $this->_arrToLeftMenu( 'shop', $items->toArray(), true );
			
			$this->leftMenu[1] = array_merge( $arr1, $arr2 );
		}
		
		if( $index == 4 ) {
			
			$Contact = new Contact();
			$items = $Contact->getListContact();
			$this->leftMenu[4] =  $this->_arrToLeftMenu( 'contact', $items->toArray(), false, true );
			
		}
		
		if( $index == 5 ) {
			
			$Categries = new Categries();
			
			$items = $Categries->getListService( 5, $this->locale );
			$this->leftMenu[5] =  $this->_arrToLeftMenu( 'cooperation', $items->toArray() );
			
		}
		
		if( $index == 6 ) {
			
			
			$Categries = new Categries();
			
			$items = $Categries->getListService( 6, $this->locale );
			$this->leftMenu[6] =  $this->_arrToLeftMenu( 'services', $items->toArray() );
			
		}
		
		if( $index == 3 ) {
			$Categries = new Categries();
			
			$items = $Categries->getListService( 3, $this->locale );
			$this->leftMenu[3] =  $this->_arrToLeftMenu( 'academy', $items->toArray() );
		}
		
		return $this->leftMenu[$index];
	}
	
	private function _arrToLeftMenu( $action, $arr, $special = false, $special2 = false ) {
		$temp = array();
		if($special2 == true)
		{
		foreach( $arr as $value ) {
			
				$value['action'] = $action . '/show/id/' .$value['c_id']. '/' . $this->view->Seo( $value['city_name']);
			
				$temp[$value['c_id']] = $value;
			
		}
		}
		else
		{
		foreach( $arr as $value ) {
			if( $special ) {
				$value['action'] = $action . '/show/id/' .$value['c_id'] . '/special/1/' . $this->view->Seo( $value['name_' . $this->locale] );
			} else {
			
				$value['action'] = $action . '/show/id/' .$value['c_id'] . '/' . $this->view->Seo( $value['name_' . $this->locale] );
			}

			if( $value['parent_id'] == 0 ) {
				$temp[$value['c_id']] = $value;
			}
		}
		
		foreach( $arr as $value ) {
			if( $special ) {
				$value['action'] = $action . '/show/id/' .$value['c_id'] . '/p/' . $value['parent_id'] . '/special/1/' . $this->view->Seo( $value['name_' . $this->locale] );
			} else {
				$value['action'] = $action . '/show/id/' .$value['c_id'] . '/p/' . $value['parent_id'] . '/' . $this->view->Seo( $value['name_' . $this->locale] );
			}

			if( $value['parent_id'] > 0 ) {
				if( isSet( $temp[$value['parent_id']] ) ) {
					$temp[$value['parent_id']]['child'][$value['c_id']] = $value;
				}
			}
		}
		}
		return $temp;
	}
}	